package l_chain_of_responsibility.b_design_pattern;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by wug on 2016/8/9 0009.
 */
public class FaceHandler implements Handler {
    @Override
    public void doFilter(Request request, Response response, FilterChain chain) {
        System.out.println("----------表情过滤 begin--------");
        String str = request.getRequestStr();
        Map<String, String> faceMap = getFacePackge();
        Set<Map.Entry<String, String>> ertrys = faceMap.entrySet();
        for (Map.Entry<String, String> entry : ertrys) {
            str = str.replaceAll("/"+entry.getKey(), entry.getValue());
        }
        request.setRequestStr(str);
        response.setResponseStr(str);
        System.out.println("----------表情过滤 end--------");
    }

    private Map<String, String> getFacePackge() {
        Map<String, String> map = new HashMap<>();
        map.put("smile","^_^");
        map.put("cry","V^V");
        return map;
    }
}
